#ifndef _PROCESS_H
#define _PROCESS_H

#include <pthread.h>
#include <arpa/inet.h>
void *thread_print(void *arg);
#define TRUE 0
#define FALSE 1

typedef void *(*work_func)(void *);
typedef struct thread_pool_task_
{
    work_func function;
    void *arg;
} thread_task_t;

typedef struct worker_thread_
{
    /*
     * If is_use !=0 and tid != 0, it means that this thread ocupies.
     * If is_use == 0, and tid != 0, manager should recycle the son thread resource.
     * If is_use ==0, and tid ==0, it means that this node is really not used.
     */
    int is_use;
    pthread_t tid;
} worker_thread_t;
typedef struct thread_pool_
{
    thread_task_t *task_list;
    int task_list_capacity;
    int task_list_cur_size;
    int task_list_front;
    int task_list_tail;

    pthread_t manager_id;
    worker_thread_t *worker_thread;
    int work_thread_min;
    int work_thread_max;
    int work_thread_live;
    //    int work_thread_num;
    pthread_mutex_t thread_busy_mutex;
    int work_thread_busy;
    int have_finish_work_num;
    int have_fail_work_num;
    int work_thread_exit;

    pthread_mutex_t thread_pool_mutex;
    pthread_cond_t producer_num;
    pthread_cond_t consumer_num;
    // pthread_cond_t destory_thread;
    int shutdown;

} thread_pool_t;

typedef struct sock_info_ {
    struct sockaddr_in sock_addr;
    int fd;
} sock_info_t;
#define SOCK_BUFF_LEN 1024

int thread_add_socket_task(thread_pool_t *thread_pool, sock_info_t *sock_info);
thread_pool_t *thread_pool_create(int min_thread_num, int max_thread_num, int task_list_capacity);
int thread_pool_destroy(thread_pool_t *thread_pool);

#endif
